﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace dao
{
    public static class SafeReader
    {
        public static string GetSafeString(SqlDataReader reader, string colName)
        {
            if (!reader.IsDBNull(reader.GetOrdinal(colName)))
                return Convert.ToString(reader[colName]);
            else
                return string.Empty;
        }

        public static int GetSafeInt(SqlDataReader reader, string colName)
        {
            if (!reader.IsDBNull(reader.GetOrdinal(colName)))
                return Convert.ToInt32(reader[colName]);
            else
                return 0;
        }

        public static DateTime GetSafeDate(SqlDataReader reader, string colName)
        {
            if (!reader.IsDBNull(reader.GetOrdinal(colName)))
                return Convert.ToDateTime(reader[colName]);
            else
                return DateTime.MinValue;
        }


        public static bool? GetSafeBoolean(SqlDataReader reader, string colName)
        {
            if (!reader.IsDBNull(reader.GetOrdinal(colName)))
                return Convert.ToBoolean(reader[colName]);
            else
                return null;
        }
    }
}
